using System;
using System.ComponentModel;
using System.Transactions;
using System.Data;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The TimeTableDetailManager class is responsible for managing BO.TimeTableDetail objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class TimeTableDetailManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all TimeTableDetail objects in the database.
        /// </summary>
        /// <returns>A list with all TimeTableDetail from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static TimeTableDetailList GetList()
        {
            return TimeTableDetailDB.GetList();
        }

        /// <summary>
        /// Gets a list with all TimeTableDetail objects in the database.
        /// </summary>
        /// <returns>A list with all TimeTableDetail from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static TimeTableDetailList GetListByDayCode(int TimeTableKey, int ClassRoomKey, Int16 DayCode)
        {
            return TimeTableDetailDB.GetListByDayCode(TimeTableKey, ClassRoomKey, DayCode);
        }

        /// <summary>
        /// Gets a single TimeTableDetail from the database without its data.
        /// </summary>
        /// <param name="timeTableKey">The TimeTableKey of the TimeTableDetail in the database.</param>
        /// <returns>A TimeTableDetail object when the TimeTableKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static TimeTableDetail GetItem(int timeTableKey)
        {
            return GetItem(timeTableKey, false);
        }

        /// <summary>
        /// Gets a single TimeTableDetail from the database.
        /// </summary>
        /// <param name="timeTableKey">The TimeTableKey of the TimeTableDetail in the database.</param>
        /// <param name="getTimeTableDetailRecords">Determines whether to load all associated TimeTableDetail records as well.</param>
        /// <returns>
        /// A TimeTableDetail object when the TimeTableKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static TimeTableDetail GetItem(int timeTableKey, bool getTimeTableDetailRecords)
        {
            TimeTableDetail myTimeTableDetail = TimeTableDetailDB.GetItem(timeTableKey);
            return myTimeTableDetail;
        }

        /// <summary>
        /// Gets a single TimeTableDetail from the database.
        /// </summary>
        /// <param name="timeTableKey">The TimeTableKey of the TimeTableDetail in the database.</param>
        /// <param name="getTimeTableDetailRecords">Determines whether to load all associated TimeTableDetail records as well.</param>
        /// <returns>
        /// A TimeTableDetail object when the TimeTableKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static DataTable GetItemByTeacherProfileKey(int timeTableKey, int teacherProfileKey, Int16 dayCode, Int16 SectionNo)
        {
            DataTable myTimeTableDetail = TimeTableDetailDB.GetItemByTeacherProfileKey(timeTableKey, teacherProfileKey, dayCode, SectionNo);
            return myTimeTableDetail;
        }

        /// <summary>
        /// Gets a single TimeTableDetail from the database.
        /// </summary>
        /// <param name="timeTableKey">The TimeTableKey of the TimeTableDetail in the database.</param>
        /// <param name="getTimeTableDetailRecords">Determines whether to load all associated TimeTableDetail records as well.</param>
        /// <returns>
        /// A TimeTableDetail object when the TimeTableKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static TimeTableDetail GetItemBySectionNo(int timeTableKey, int classRoomKey, Int16 dayCode, Int16 SectionNo)
        {
            TimeTableDetail myTimeTableDetail = TimeTableDetailDB.GetItemBySectionNo(timeTableKey, classRoomKey, dayCode, SectionNo);
            return myTimeTableDetail;
        }


        public static DataTable GetListTableByClassRoomKey(int timeTableKey, int classRoomKey)
        {
            return TimeTableDetailDB.GetListTableByClassRoomKey(timeTableKey, classRoomKey);
        }

        /// <summary>
        /// Saves a TimeTableDetail in the database.
        /// </summary>
        /// <param name="myTimeTableDetail">The TimeTableDetail instance to save.</param>
        /// <returns>The new TimeTableKey if the TimeTableDetail is new in the database or the existing TimeTableKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(TimeTableDetail myTimeTableDetail)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int timeTableDetailTimeTableKey = TimeTableDetailDB.Save(myTimeTableDetail);

                //  Assign the TimeTableDetail its new (or existing TimeTableKey).
                myTimeTableDetail.TimeTableKey = timeTableDetailTimeTableKey;

                myTransactionScope.Complete();

                return timeTableDetailTimeTableKey;
            }
        }

        /// <summary>
        /// Deletes a TimeTableDetail from the database.
        /// </summary>
        /// <param name="myTimeTableDetail">The TimeTableDetail instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        //[DataObjectMethod(DataObjectMethodType.Delete, true)]
        //public static bool Delete(TimeTableDetail myTimeTableDetail)
        //{
        //    return TimeTableDetailDB.Delete(myTimeTableDetail.TimeTableKey);
        //}

        /// <summary>
        /// Deletes a TimeTableDetail from the database.
        /// </summary>
        /// <param name="myTimeTableDetail">The TimeTableDetail instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(int timeTableKey, int timeTableDetailKey)
        {
            return TimeTableDetailDB.Delete(timeTableKey, timeTableDetailKey);
        }

        #endregion

    }

}
